class MaterialNode extends MyNode{
    constructor($state='new',...obj){
        super('Material',$state,{
            name:"材料名称"
        },...obj);
    }

    getTypeName(){
        return "材料";
    }

    getTemplate(edge,g){
        return `
 <div class="form-group">
    <label class="col-sm-2 control-label">材料</label>
     <div class="col-sm-10">
    <select class="form-control"
    data-ng-options="material.name for material in materials"
    data-ng-model="component_ref" 
    data-ng-change="graph.resetLink(${edge},component_ref,reloadGraph)"
    data-ng-init="component_ref=graph.getNodeFromList('${this.id}',materials)"
    ></select>
 </div>
 </div>
 
 <div class="form-group">
 <label class="col-sm-2 control-label">操作</label>
 <p class="col-sm-10 form-control-static">
 <a class="btn" href="javascript:;" ng-click="removeEdge(${edge})">删除当前节点</a>
</p>
</div>
`;
    }

    static loadMaterials(){
        let session = neo4jService.getSession();
        let resultPromise = session.run(`MATCH (n:Material) RETURN n`);
        resultPromise.then(result => {
            session.close();
            MaterialNode.materials = result.records
                .map((record) => record.get(0))
                .map(node => MyNode.fromNeo4jNode(node));
            for (let fn of MaterialNode.loadMaterials.callbacks){
                fn(MaterialNode.materials);
            }
        });
    }

    static loadMaterialsFrom(superId,...callbacks){
        let session = neo4jService.getSession();
        let resultPromise = session.run(`start s=node(${superId}) MATCH (s)-[*]->(n:Material) RETURN n`);
        resultPromise.then(result => {
            session.close();
            let components = result.records
                .map((record) => record.get(0))
                .map(node => MyNode.fromNeo4jNode(node));
            for (let fn of callbacks){
                fn(components);
            }
        });
    }
}
MaterialNode.materials=[];
// ComponentNode.loadComponents();
MaterialNode.loadMaterials.callbacks=[];
